<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User extends User_Controller
{
	private $response = array();
    public function __construct()
    {
        parent::__construct();
        
    }

    // Sample call: http://api.kanding.com/user/f2607e0e3e3efb8f-2012/register/jomel/admin
    // Result: {"message":"success","data":{"username":"jomel","password":"admin"}}
	public function index($api, $method=null, $username=null, $password=null, $client_id=null)
	{
		$user = $this->load->model('User_Model');
		if($api == 'f2607e0e3e3efb8f-2012') {
			// TODO: check database for a valid client...
			//echo sha1(md5($api));
			switch($method){
				case 'register':
					$info = array('username'=>$username,'password'=>$password);
					//$id = $this->User_Model->save($info);
					//if($id){
						$response["message"] = "success";
						$response["data"] = $info;
						$data["response"] = JSONUtils::toJSON($response);
					//}
					break;
					
				case 'login':
					$data = $user->login($username, $password);
					break;
			}
		}

        $this->load->view('user', $data);
	}
	
}